package club.drguo.mapreduce.wordcount;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

/**
 * 本地
 * @author guo
 *
 */
//club.drguo.hadoop.mapreduce.WordCountRunner
public class WordCountRunner2 {
	public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
		Configuration configuration = new Configuration();
		Job job = Job.getInstance(configuration);
		//设置job中的资源所在的jar包（指明main方法所在类）
//		job.setJarByClass(WordCountRunner2.class);
		//job要使用哪个mapper类
		job.setMapperClass(WordCountMapper.class);
		//job要使用哪个reducer类
		job.setReducerClass(WordCountReducer.class);
		//job的mapper类输出的kv数据类型
		job.setMapOutputKeyClass(Text.class);
		job.setMapOutputValueClass(LongWritable.class);
		//job的reducer类输出的kv数据类型
		job.setOutputKeyClass(Text.class);
		job.setOutputValueClass(LongWritable.class);
		//指定要处理的数据所存放的路径(不是指定某一个文件，而是该路径下的所有文件)
		FileInputFormat.setInputPaths(job, "/home/guo/data/input");
		//指定处理结果所存放的路径
		FileOutputFormat.setOutputPath(job, new Path("/home/guo/data/output"));
		//显示进度
		boolean b = job.waitForCompletion(true);
		System.out.println(b?"完成":"未完成");
	}
}
